﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text;

namespace MayhemPowerShell
{
    public static class PowerShellExtensionMethods
    {
        public static List<T> Execute<T>(this PowerShell shell)
        {
            var results = shell.Invoke<T>();
            shell.Commands.Clear();
            return results.ToList();
        }

        public static List<PSObject> Execute(this PowerShell shell)
        {
            return shell.Execute<PSObject>();
        }

        public static List<T> ExecuteScript<T>(this PowerShell shell, String script)
        {
            shell.Commands.Clear();
            return shell.AddScript(script).Execute<T>();
        }

        public static List<PSObject> ExecuteScript(this PowerShell shell, String script)
        {
            return shell.ExecuteScript<PSObject>(script);
        }
    }
}
